package com.lzs.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzs.entity.Dict;
import com.lzs.system.service.DictService;
import com.lzs.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 基础字典 前端控制器
 * </p>
 *
 * @author ymw
 * @since 2020-12-09
 */
@RestController
@RequestMapping("/system/dict")
public class DictController {
    @Autowired
    private DictService dictService;
    @PostMapping("/selectAllDictPage/{page}/{limit}")
    @ApiOperation(value = "字典分页查询")
    public Page<Dict> selectAllDictPage(@PathVariable Integer page, @PathVariable Integer limit, @RequestBody Dict dict){
        Page<Dict> dictPage = dictService.selectAllDictPage(page, limit, dict);
        return dictPage;
    }

    // 新增修改
    @PostMapping("/insertOrUpdateDict")
    @ApiOperation(value = "字典新增修改")
    public R insertOrUpdateDict(@RequestBody Dict dict){
        return dictService.insertOrUpdateDict(dict);
    }
    // 修改时回显内容
    @GetMapping("/findByDictId/{dictId}")
    @ApiOperation(value = "修改时回显内容")
    public R findByDictId(@PathVariable Long dictId){
        return dictService.findByDictId(dictId);
    }
    // 根据Id删除
    @DeleteMapping("/deleteDict/{dictId}")
    @ApiOperation(value = "根据子典Id删除")
    public R deleteDict(@PathVariable Long dictId){
        boolean b = dictService.removeById(dictId);
        if (b){
            return R.ok().message("删除成功");
        }
        return R.ok().message("删除失败");
    }
}

